/**
 * @title AttentionListManager.java
 * @package com.esun.cheetah.common
 * @description 关注列表管理，该类主要用于关注状态的本地同步
 * @author liugan
 * @date 2012-5-10
 * @copyright 深圳市易讯天空
 */
package com.esun.cheetah.biz.personal.attention;

import java.util.ArrayList;

import android.text.TextUtils;
import com.esun.cheetah.model.personal.attention.AttentionGameInfo;

/**
 * @title AttentionListManager
 * @description 关注列表管理
 * @author liugan
 */
public class AttentionListManager {
	/** 关注列表 */
	private ArrayList<AttentionGameInfo> attentionListDone = new ArrayList<AttentionGameInfo>();
	private ArrayList<AttentionGameInfo> attentionListRightNow = new ArrayList<AttentionGameInfo>();
	private ArrayList<AttentionGameInfo> attentionListFuture = new ArrayList<AttentionGameInfo>();

	private volatile boolean attentionListChanged;
	private volatile boolean attentionListAdded;

	private static AttentionListManager instance = new AttentionListManager();

	private AttentionListManager() {
	}

	public static AttentionListManager getInstance() {
		return instance;
	}

	public synchronized void setAttentionListDone(
			ArrayList<AttentionGameInfo> listDone) {
		attentionListDone.clear();
		attentionListDone.addAll(listDone);
	}

	public synchronized void setAttentionListRightNow(
			ArrayList<AttentionGameInfo> listRightNow) {
		attentionListRightNow.clear();
		attentionListRightNow.addAll(listRightNow);
	}

	public synchronized void setAttentionListFuture(
			ArrayList<AttentionGameInfo> listFuture) {
		attentionListFuture.clear();
		attentionListFuture.addAll(listFuture);
	}

	public synchronized ArrayList<AttentionGameInfo> getAttentionListDone() {
		return attentionListDone;
	}

	public synchronized ArrayList<AttentionGameInfo> getAttentionListRightNow() {
		return attentionListRightNow;
	}

	public synchronized ArrayList<AttentionGameInfo> getAttentionListFuture() {
		return attentionListFuture;
	}

	/**
	 * @title updateAttentionState
	 * @description 在关注列表里更新关注状态
	 * @param matchId
	 */
	public synchronized void updateCancelAttention(String matchId) {
		if (TextUtils.isEmpty(matchId)) {
			return;
		}
		// 遍历已完场的关注比赛列表
		for (int i = 0; i < attentionListDone.size(); i++) {
			AttentionGameInfo info = attentionListDone.get(i);
			if (matchId.equals(info.getMatchid())) {
				attentionListDone.remove(i);
				attentionListChanged = true;
				break;
			}
		}

		for (int i = 0; i < attentionListFuture.size(); i++) {
			AttentionGameInfo info = attentionListFuture.get(i);
			if (matchId.equals(info.getMatchid())) {
				attentionListFuture.remove(i);
				attentionListChanged = true;
				break;
			}
		}

		for (int i = 0; i < attentionListRightNow.size(); i++) {
			AttentionGameInfo info = attentionListRightNow.get(i);
			if (matchId.equals(info.getMatchid())) {
				attentionListRightNow.remove(i);
				attentionListChanged = true;
				break;
			}
		}
	}

	public synchronized boolean isAttentionListChanged() {
		return attentionListChanged;
	}

	public synchronized void setAttentionListChanged(
			boolean attentionListChanged) {
		this.attentionListChanged = attentionListChanged;
	}

	public synchronized boolean isAttentionListAdded() {
		return attentionListAdded;
	}

	public synchronized void setAttentionListAdded(boolean attentionListAdded) {
		this.attentionListAdded = attentionListAdded;
	}

}
